package com.bw.dao.impl;

import com.bw.dao.RoleDao;
import com.bw.pojo.Role;

import java.util.List;

public class RoleDaoImpl extends BaseDao implements RoleDao {
    @Override
    public List<Role> getRoleList(Role role) {
        String sql = "select * from r_role where is_res = 0 ";
        if(null != role.getUsername() && !role.getUsername().isEmpty()){
            sql += " and INSTR(username,'"+role.getUsername()+"')";
        }
        List<Role> list = baseQueryList(Role.class, sql);
        return list;
    }

    @Override
    public void addGet(Role role) {
        String sql = "insert into r_role (username,remark,is_res) values (?,?,0)";
        baseUpdate(sql, role.getUsername(),role.getRemark());
    }

    @Override
    public void roleDel(Integer rid) {

    }

    @Override
    public void getToDel(String uids) {
        String sql = "update r_role set is_res = 1 where rid in ("+uids+")";
        baseUpdate(sql);
    }

    @Override
    public Role findByIn(Integer id) {
        String sql = "select * from r_role where rid = ?";
        Role role = baseQueryOne(Role.class, sql, id);
        return role;
    }

    @Override
    public void getUpd(Role role) {
        String sql = "update r_role set username=?,remark=? where rid = ?";
        baseUpdate(sql,role.getUsername(),role.getRemark(),role.getRid());
    }
}
